package com.digitalchina.lxnsy.sy.main;

import android.webkit.JavascriptInterface;

import androidx.annotation.NonNull;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.digitalchina.lxnsy.activity.old.ActivityManagerListActivity;
import com.digitalchina.lxnsy.activity.old.ExpertsListActivity;
import com.digitalchina.lxnsy.activity.old.LoginGuideActivity;
import com.digitalchina.lxnsy.activity.old.MainActivity;
import com.digitalchina.lxnsy.activity.old.MyCollectActivity;
import com.digitalchina.lxnsy.activity.old.PersonnelServiceListActivity;
import com.digitalchina.lxnsy.activity.old.ShareFarmManagerActivity;
import com.digitalchina.lxnsy.activity.old.SheepListActivity;
import com.digitalchina.lxnsy.base.BaseHtmlFragment;
import com.digitalchina.lxnsy.sy.login.LoginActivity;
import com.digitalchina.lxnsy.sy.login.RegisterAndLoginActivity;
import com.digitalchina.lxnsy.sy.peopleAddExp.ChangePhoneActivity;
import com.digitalchina.lxnsy.sy.peopleAddExp.MyAdviceActivity;
import com.digitalchina.lxnsy.sy.peopleAddExp.MyProfileCommonActivity;
import com.digitalchina.lxnsy.sy.peopleAddExp.MyProfileExpertActivity;
import com.digitalchina.lxnsy.sy.peopleAddExp.MyRresponseActivity;
import com.digitalchina.lxnsy.sy.peopleAddExp.UpdatePasswordActivity;
import com.digitalchina.lxnsy.toolkit.ActivityTaskManager;
import com.digitalchina.lxnsy.toolkit.GotoUtil;
import com.digitalchina.lxnsy.toolkit.SharedPreferencesUtil;
import com.digitalchina.lxnsy.toolkit.ToastUtil;
import com.digitalchina.lxnsy.xml.AdminXML;
import com.digitalchina.lxnsy.xml.UserXML;
import com.digitalchina.lxnsy.zbsy.TagManageAddActivity;


public class Main4Fragment extends BaseHtmlFragment {
    @Override
    protected void loadHtml() {
        webView.addJavascriptObject(new JsApi(), null);
        loadUrl("myProfile");
        hideActionBar();

    }

    @Override
    public void rightOnClick() {


    }


    public class JsApi {

        @JavascriptInterface
        public void registerAndLogin(Object msg) {//普通信息修改
            go(LoginActivity.class);
        }

        @JavascriptInterface
        public void myProfile_common(Object msg) {//普通信息修改
            noLoginToSkip(MyProfileCommonActivity.class);
        }


        @JavascriptInterface
        public void myProfile_expert(Object msg) {//专家信息修改
            noLoginToSkip(MyProfileExpertActivity.class);
        }

        @JavascriptInterface
        public void myAdvice(Object msg) {//我的咨询
            noLoginToSkip(MyAdviceActivity.class);

        }

        @JavascriptInterface
        public void myRresponse(Object msg) {//我的回复
            noLoginToSkip(MyRresponseActivity.class);
        }


        @JavascriptInterface
        public void myShouCang(Object msg) {//我的收藏
            noLoginToSkip(MyCollectActivity.class);
        }

        @JavascriptInterface
        public void activeManage(Object msg) {//活动管理
            noLoginToSkip(ActivityManagerListActivity.class);
        }

        @JavascriptInterface
        public void sheepGX(Object msg) {//良种羊
            if ("1".equals(UserXML.getLoginStatus(getActivity()))) {
                GotoUtil.gotoActivity(getActivity(), SheepListActivity.class, "key", "mytalents");
            } else {
                GotoUtil.gotoActivity(getActivity(), LoginActivity.class);
            }
        }

        @JavascriptInterface
        public void personManage(Object msg) {//人才
            if ("1".equals(UserXML.getLoginStatus(getActivity()))) {
                GotoUtil.gotoActivity(getActivity(), PersonnelServiceListActivity.class, "key", "mytalents");
            } else {
                GotoUtil.gotoActivity(getActivity(), LoginActivity.class);
            }
        }

        @JavascriptInterface
        public void shareManage(Object msg) {//共享管理
            noLoginToSkip(ShareFarmManagerActivity.class);
        }

        @JavascriptInterface
        public void about(Object msg) {//关于


//            go(TagManageAddActivity.class);

        }
        @JavascriptInterface
        public void jiance(Object msg) {//检测更新



        }

        @JavascriptInterface
        public void forgetPassword(Object msg) {//修改密码
            noLoginToSkip(UpdatePasswordActivity.class);
        }

        @JavascriptInterface
        public void changePhone(Object msg) {//修改手机
            noLoginToSkip(ChangePhoneActivity.class);
        }

        @JavascriptInterface
        public void outLogin(Object msg) {//退出登录
            if ("1".equals(UserXML.getLoginStatus(getActivity()))) {
                exitLogin();
            }
        }

    }


    public void exitLogin() {
        new MaterialDialog.Builder(getActivity())
                .title("提示")
                .content("您确定要退出登录吗？")
                .positiveText("确定")
                .negativeText("取消")
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        SharedPreferencesUtil.cleanXml(getActivity(), AdminXML.NAME);
                        UserXML.setLoginStatus(getActivity(),"0");
                        go(MainActivity.class);
                        ActivityTaskManager.getInstance().closeAllActivity();
                    }
                })
                .show();
    }
}
